package 回溯算法;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class 子集Ⅱ {

    //不使用used判断
    class Solution{
        List<List<Integer>> result = new ArrayList<>();
        LinkedList<Integer> path = new LinkedList<>();
        public List<List<Integer>> subsetsWithDup(int[] nums){
            Arrays.sort(nums);
            backTracing(nums,0);
            return result;
        }

        private void backTracing(int[] nums, int startIndex) {
            result.add(new ArrayList<>());
            for (int i = startIndex; i < nums.length; i++) {
                if (i>startIndex&&nums[i]==nums[i-1]){
                    //退出目前这个循环 继续下一个循环
                    continue;
                }
                path.add(nums[i]);
                backTracing(nums,i+1);
                path.removeLast();
            }
        }
    }
}
